#include "../include/NxServiceAPI_C.h"

//////////////////////////////////////////////////////////////////////////
/* INjServer */

extern "C" NJGIS_SERVICE void* njgis_service_createServerHandle( char* ip, int port )
{
	NJGIS::SERVICE::INjServerFactory* pServerFactory = NJGIS::SERVICE::createServerFactory();
	NJGIS::SERVICE::INjServer* pServer =  pServerFactory->createServer(ip, port);
	return pServer;
}

extern "C" NJGIS_SERVICE void* njgis_service_createServiceAccessHandle( void* server )
{
	NJGIS::SERVICE::INjServiceAccess* pAccess = ((NJGIS::SERVICE::INjServer*)server)->getServiceAccess();
	return pAccess;
}

//////////////////////////////////////////////////////////////////////////
/* INjServiceAccess */

extern "C" NJGIS_SERVICE void* njgis_service_createModelServiceList( void* access )
{
	std::vector<NJGIS::SERVICE::INjModelService*>* list = new std::vector<NJGIS::SERVICE::INjModelService*>;
	((NJGIS::SERVICE::INjServiceAccess*)access)->getModelServicesList(*list);
	return list;
}

extern "C" NJGIS_SERVICE int njgis_service_cleanModelServiceListHandle( void* list )
{
	 delete (std::vector<NJGIS::SERVICE::INjModelService*>*)list;
	 return 1;
}

extern "C" NJGIS_SERVICE int njgis_service_getModelServiceCount( void* list )
{
	return ((std::vector<NJGIS::SERVICE::INjModelService*>*)list)->size();
}

extern "C" NJGIS_SERVICE void* njgis_service_getModelServiceByIndex( void* list, int index )
{
	return (*((std::vector<NJGIS::SERVICE::INjModelService*>*)list))[index];
}

extern "C" NJGIS_SERVICE void* njgis_service_createDataConfiguration( void* access )
{
	return ((NJGIS::SERVICE::INjServiceAccess*)access)->createDataConfig();
}

//////////////////////////////////////////////////////////////////////////
/* INjModelService */

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceOID( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceOID();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceName( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceName();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceType( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceType();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceDetailURL( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceDetailURL();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServicePID( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServicePid();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceMID( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceMid();
}

extern "C" NJGIS_SERVICE bool njgis_service_getModelServiceRegistered( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceRegister();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceVersion( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceVersion();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceDescription( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceDescription();
}

extern "C" NJGIS_SERVICE int njgis_service_getModelServicePlatform( void* ms )
{
	return (int)((NJGIS::SERVICE::INjModelService*)ms)->getServicePlatform();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceDeploymentTime( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getDeploymentTime();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceIMG( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getImage();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceDeployorName( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceDeployorName();
}

extern "C" NJGIS_SERVICE const char* njgis_service_getModelServiceDeployorEmail( void* ms )
{
	return ((NJGIS::SERVICE::INjModelService*)ms)->getServiceDeployorEmail();
}

extern "C" NJGIS_SERVICE int njgis_service_getModelServiceStatus( void* ms )
{
	return (int)((NJGIS::SERVICE::INjModelService*)ms)->getServiceStatus();
}

extern "C" NJGIS_SERVICE int njgis_service_getModelServiceLimitation( void* ms )
{
	return (int)((NJGIS::SERVICE::INjModelService*)ms)->getServiceLimitation();
}

extern "C" NJGIS_SERVICE int njgis_service_getModelServicePermission( void* ms )
{
	return (int)((NJGIS::SERVICE::INjModelService*)ms)->getServicePermission();
}

extern "C" NJGIS_SERVICE const char* njgis_service_serviceInvoke( void* ms, void* config)
{
	std::string record;
	if (((NJGIS::SERVICE::INjModelService*)ms)->invoke((NJGIS::SERVICE::INjDataConfiguration*)config, record) > 0)
	{
		return record.c_str();
	}
	return "";
}

extern "C" NJGIS_SERVICE void njgis_service_serviceRefresh( void* ms )
{
	((NJGIS::SERVICE::INjModelService*)ms)->refresh();
}

//////////////////////////////////////////////////////////////////////////
/* INjDataConfiguration */

extern "C" NJGIS_SERVICE int njgis_service_getDataConfigurationCount( void* config )
{
	return ((NJGIS::SERVICE::INjDataConfiguration*)config)->getCount();
}

extern "C" NJGIS_SERVICE int njgis_service_insertConfigurationData( void* config, char* state, char* eventname, char* dataid, bool destoryed, bool requested, bool optional )
{
	return ((NJGIS::SERVICE::INjDataConfiguration*)config)->insertData(state, eventname, dataid, destoryed, requested, optional);
}

extern "C" NJGIS_SERVICE const char* njgis_service_getConfigurationData( void* config, char* state, char* eventname )
{
	return ((NJGIS::SERVICE::INjDataConfiguration*)config)->getDataID(state, eventname);
}
